//
//  MyInfoBaseViewContorller.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/4/24.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "MyInfoBaseViewContorller.h"
#import "TraderMiddleManFooterView.h"
#import "addView.h"
#import "UIView+tapAction.h"

#import "TraderSeachByTimeViewController.h"
#import "TraderSeachBySiteViewController.h"
#import "TraderSeachByStoreViewController.h"
#import "TraderSeachByMiddleManViewController.h"

@interface MyInfoBaseViewContorller()<TraderMiddleManFooterViewDelegate>
@property(nonatomic,strong)  TraderMiddleManFooterView  *footerView;

@end

@implementation MyInfoBaseViewContorller

-(void)viewDidLoad
{
    [super viewDidLoad];
//        if (self.isTwoRightItem) //右边是有2个按钮
//    {
//        [self addRightEditItemAndAddItem];
//        [self  addSearchBarView];
//    }
//    else //右边只有一个添加按钮
//    {
//        [self addRightAddItem];
//    }
    

}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.flag1 = 0;
    self.isShowTickBtn = NO;
}
#pragma mark 添加了“添加“和”编辑“2个
-(void)addRightEditItemAndAddItem
{
    
//    UIView *editItem = [addView addViewInitWithXib];
//    editItem.frame = CGRectMake(50,0,44,44);
//    [editItem setBackgroundColor:[UIColor clearColor]];
////    [[UIView alloc]initWithFrame:];
//    [editItem addTapGestureWithTarget:self action:@selector(clickAddItem)];
//    UIButton *EditBtn  = [[UIButton alloc]initWithFrame:CGRectMake(50,0,25,25)];
    
//    [EditBtn setImage:[UIImage imageNamed:@"add_icon"] forState:UIControlStateNormal];
//    [EditBtn addTarget:self action:@selector(clickAddItem) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:[self definedRightAddItem]];
    
    UIButton *addBtn  = [[UIButton alloc]initWithFrame:CGRectMake(0,0,25,25)];
    [addBtn setImage:[UIImage imageNamed:@"biaoji_icon"] forState:UIControlStateNormal];
    [addBtn addTarget:self action:@selector(clickEditItem) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem2 = [[UIBarButtonItem alloc]initWithCustomView:addBtn];
    
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:[self definedRightAddItem],rightItem2, nil];
    
}


#pragma mark 只有一个“添加”按钮
-(void)addRightAddItem
{
//    UIButton *EditBtn  = [[UIButton alloc]initWithFrame:CGRectMake(40,0,25,25)];
//    [EditBtn setImage:[UIImage imageNamed:@"add_icon"] forState:UIControlStateNormal];
//    [EditBtn addTarget:self action:@selector(clickAddItem) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:EditBtn];
    
    self.navigationItem.rightBarButtonItem = [self definedRightAddItem];
}

-(UIBarButtonItem *)definedRightAddItem
{
    UIView *editItem = [addView addViewInitWithXib];
    editItem.frame = CGRectMake(50,0,44,44);
    [editItem setBackgroundColor:[UIColor clearColor]];
    //    [[UIView alloc]initWithFrame:];
    [editItem addTapGestureWithTarget:self action:@selector(clickAddItem)];
    //    UIButton *EditBtn  = [[UIButton alloc]initWithFrame:CGRectMake(50,0,25,25)];
    
    //    [EditBtn setImage:[UIImage imageNamed:@"add_icon"] forState:UIControlStateNormal];
    //    [EditBtn addTarget:self action:@selector(clickAddItem) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:editItem];
    return rightItem;

}

#pragma mark 添加搜索栏
-(void)addSearchBarView
{
//    SearchBarView *searchBarView = [SearchBarView searchBarViewWithXib];
//    searchBarView.frame = CGRectMake(0, 64, UIScreenWidth, 40);
//    [self.view addSubview:searchBarView];
}
#pragma mark 点击了编辑按钮
-(void)clickAddItem
{

}
#pragma mark 点击了编辑按钮
-(void)clickEditItem
{
    if (!self.isShowTickBtn)
    {
        [[NSNotificationCenter defaultCenter]postNotificationName:@"moveTickBtnToSee" object:nil];
        [self addFooterView];
        self.isShowTickBtn = YES;
        
    }
    else
    {
        [[NSNotificationCenter defaultCenter]postNotificationName:@"moveTickBtnToNotSee" object:nil];
        [self removeFooterView];
        self.isShowTickBtn = NO;
    }
    
}

#pragma mark 把cell左边的打勾图片移动看不见
-(void)removeFooterView;
{
    [self.footerView removeFromSuperview];
    
    CGFloat tableViewX = self.tableView.frame.origin.x;
    CGFloat tableViewY = self.tableView.frame.origin.y;
    CGFloat tableViewWidth = UIScreenWidth;
    CGFloat tableViewHight = self.tableView.frame.size.height + 44;
    self.tableView.frame = CGRectMake(tableViewX, tableViewY, tableViewWidth, tableViewHight);
    

}
#pragma mark 添加底部的view，放按钮“全选，移动，启用，禁用”
-(void)addFooterView
{
    TraderMiddleManFooterView *footerView;
    NSLog(@"%d-----%d",self.type,self.type == isCustomerOfMiddleMan);
    if (self.type == isCustomerOfMiddleMan)
    {
          footerView = [TraderMiddleManFooterView TraderMiddleManFooterViewWithXibWithIsShowRemoveBtn:NO];
    }
    else
    {
          footerView = [TraderMiddleManFooterView TraderMiddleManFooterViewWithXibWithIsShowRemoveBtn:YES];
    }
    
    CGFloat footerViewY = MAIN_SCREEN_bounds.size.height - footerView.frame.size.height;
    CGFloat footerViewWidth = MAIN_SCREEN_bounds.size.width;
    CGFloat footerViewHeight = 44;
    footerView.frame = CGRectMake(0,footerViewY,footerViewWidth ,footerViewHeight);
    self.footerView = footerView;
    [self.view addSubview:self.footerView];
    self.footerView.delegate = self;
    
    
    CGFloat tableViewX = self.tableView.frame.origin.x;
    CGFloat tableViewY = self.tableView.frame.origin.y;
    CGFloat tableViewWidth = UIScreenWidth;
    CGFloat tableViewHight = self.tableView.frame.size.height - footerViewHeight;
    self.tableView.frame = CGRectMake(tableViewX, tableViewY, tableViewWidth, tableViewHight);

}

#pragma mark 添加右边的查询图片
-(void)addSearchRightItem
{
    UIButton *EditBtn  = [[UIButton alloc]initWithFrame:CGRectMake(40,0,25,25)];
    [EditBtn setImage:[UIImage imageNamed:@"icon27"] forState:UIControlStateNormal];
    [EditBtn addTarget:self action:@selector(clickSearchItem) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:EditBtn];
    
    self.navigationItem.rightBarButtonItem = rightItem;
}

-(void)clickSearchItem;
{
    
}

#pragma mark 展示右边“周期查询，楼盘查询，。。。的view
-(void)showSearhRightItemView;
{
//    searchView11 *view = [searchView11 searchInitWithXib];
//    CGFloat viewW= view.frame.size.width;
//    CGFloat viewH = view.frame.size.height;
//    view.frame = CGRectMake(UIScreenWidth - viewW, 64, viewW, viewH);
//    self.searchView = view;
//    [self.view addSubview:self.searchView];
//    self.showSearchView = YES;
//    self.searchView.delegate = self;
}

#pragma mark 周期查询
-(void)searchViewClickSeachByTime;
{
    TraderSeachByTimeViewController  *vc = [[TraderSeachByTimeViewController alloc]initWithNibName:@"TraderSeachByTimeViewController" bundle:nil];
    [self.navigationController pushViewController:vc animated:YES];
    [self hiddenSearchView];
    
}
#pragma mark 楼盘查询
-(void)searchViewClickSeachBySite;
{
    TraderSeachBySiteViewController  *vc = [[TraderSeachBySiteViewController alloc]initWithNibName:@"TraderSeachBySiteViewController" bundle:nil];
    [self.navigationController pushViewController:vc animated:YES];
    [self hiddenSearchView];
}
#pragma mark 门店查询
-(void)searchviewclickSeachByStore;
{
    TraderSeachByStoreViewController  *vc = [[TraderSeachByStoreViewController alloc]initWithNibName:@"TraderSeachByStoreViewController" bundle:nil];
    [self.navigationController pushViewController:vc animated:YES];
    [self hiddenSearchView];
    
}

#pragma mark 经纪人查询
-(void)searchviewclickSeachByMiddleMan
{
    TraderSeachByMiddleManViewController *vc = [[TraderSeachByMiddleManViewController alloc]initWithNibName:@"TraderSeachByMiddleManViewController" bundle:nil];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 隐藏searchview
-(void)hiddenSearchView
{
//    [self.searchView removeFromSuperview];
//    self.showSearchView = NO;
}

#pragma mark traderMiddleManFootVIew代理，点击了上边的按钮触发
-(void)tradermiddleManFooterViewClickBtnWithTag:(NSInteger)btnTag andImgTag:(NSInteger)imgTag
{
    if (btnTag == 0)//点击了全选按钮
    {
        NSNumber *imgNum = [NSNumber numberWithInteger:imgTag];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"selectAllMiddleMan" object:imgNum];
    }
    else if (imgTag == 1)
    {
        if (btnTag == 2 || btnTag == 3)
        {
            NSNumber *tag = [NSNumber numberWithInteger:btnTag];
            [[NSNotificationCenter defaultCenter]postNotificationName:@"forbiddenMiddleMan" object:tag];
        }
        else
        {
            NSLog(@"点击了移动按钮");
        }
    }
}



    
@end
